Expand description

Workers are a way to offload tasks to web workers. These are run concurrently using web-workers.

Types of Workers

Reaches

  • Public - There will exist at most one instance of a Public Worker at any given time. Bridges will spawn or connect to an already spawned worker in a web worker. When no bridges are connected to this worker, the worker will disappear.

  • Private - Spawn a new worker in a web worker for every new bridge. This is good for moving shared but independent behavior that communicates with the browser out of components. When the the connected bridge is dropped, the worker will disappear.

Communicating with workers

Bridges

A bridge allows bi-directional communication between an worker and a component. Bridges also allow workers to communicate with one another.

Dispatchers

A dispatcher allows uni-directional communication between a component and an worker. A dispatcher allows a component to send messages to an worker.

Overhead

Workers use web workers (i.e. Private and Public). They incur a serialization overhead on the messages they send and receive. Workers use bincode to communicate with other browser worker, so the cost is substantially higher than just calling a function.

Structs

A newtype around a bridge to indicate that it is distinct from a normal bridge

Id of responses handler.

Create a new instance for every bridge.

Create a single instance in a tab.

Link to worker’s scope for creating callbacks.

Traits

Bridge to a specific kind of worker.

This trait allows registering or getting the address of a worker.

This trait allows the creation of a dispatcher to an existing worker that will not send replies when messages are sent.

A trait to enable private workers being registered in a web worker.

A trait to enable public workers being registered in a web worker.

Declares the behavior of the worker.

Type Definitions

Alias for Rc<dyn Fn(IN)>

Alias for Rc<RefCell<T>>